﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

namespace Jzy.Web.test
{
    public partial class Image : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Bitmap image = new Bitmap(500, 300);
          
            Graphics g = Graphics.FromImage(image);
            g.Clear(Color.White);

            g.DrawLine(new Pen(Color.Red, 2), new Point(0, 0), new Point(100, 100));
            Rectangle rec = new Rectangle(new Point(100, 0), new Size(50, 50));

            g.DrawRectangle(new Pen(Color.Yellow, 2), rec);
            

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);




            Response.ClearContent();
            Response.ContentType = "image/Jpeg";
            Response.BinaryWrite(ms.ToArray());
        }

        public void DrawRoundRectange(Graphics g, int x, int y, int width, int height)
        {
            //设置画图时的滤波模式为消除锯齿现象
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            //创建一个红色的画笔
            Pen pen = new Pen(Color.Red);
            //画矩形上面的边
            g.DrawLine(pen, x + 10, y, width, y);
            //画矩形下面的边
            g.DrawLine(pen, x + 10, y + height, width, y + height);
            //画矩形左面的边
            g.DrawLine(pen, x, y + 10, x, y + height - 10);
            //画矩形右面的边
            g.DrawLine(pen, x + width, y + 10, x + width, y + height - 10);
            //画矩形左上角的圆角
            g.DrawArc(pen, x, y, 20, 20, 180, 90);
            //画矩形右下角的圆角
            g.DrawArc(pen, x + width - 20, y + height - 20, 20, 20, 360, 90);
            //画矩形右上角的圆角
            g.DrawArc(pen, x + width - 20, y, 20, 20, 270, 90);
            //画矩形左下角的圆角
            g.DrawArc(pen, x, y + height - 20, 20, 20, 90, 90);
        }

    }
}
